﻿namespace Raven
{
    public class FuzzySetTriangle : FuzzySet
    {
        private Fix _peakPoint;
        private Fix _leftOffset;
        private Fix _rightOffset;

        public FuzzySetTriangle(Fix peak, Fix left, Fix right) : base(peak)
        {
            _peakPoint = peak;
            _leftOffset = left;
            _rightOffset = right;
        }

        public override Fix CalculateDOM(Fix val)
        {
            if ((_peakPoint == val && _rightOffset == 0) || (_peakPoint == val && _leftOffset == 0))
            {
                return 1;
            }
            else if (val >= _peakPoint && val < _peakPoint + _rightOffset)
            {
                return (val - _peakPoint) / -_rightOffset + 1;
            }
            else if (val <= _peakPoint && val >= _peakPoint - _leftOffset)
            {
                return (val - (_peakPoint - _leftOffset)) / _leftOffset;
            }
            else
            {
                return 0;
            }
        }
    }
}